<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="hexo,博客,hexo3,blog,github pages,免费个人博客" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="通过一些博客和《啊哈！算法》了解js的栈，队列 队列问题 队列的定义：队列是一种特 殊的线性结构,它只允许在队列的首部(head)进行删除操作,这称为“出队”,而在队列 的尾部(tail)进行插入操作,这称为“入队”。当队列中没有元素时(即 head==tail),称为 空队列  《啊哈！算法》中的一道题，大体意思是有一串密码规则为：首先将第 1 个数删除,紧接着将第 2 个数放到 这串数的末尾,">
<meta name="keywords" content="hexo,博客,hexo3,blog,github pages,免费个人博客">
<meta property="og:type" content="article">
<meta property="og:title" content="js的简单算法(二)">
<meta property="og:url" content="http://lanbos.win/2016/09/27/reading/arithmetic_fun02/index.html">
<meta property="og:site_name" content="lanbos&#39;blog">
<meta property="og:description" content="通过一些博客和《啊哈！算法》了解js的栈，队列 队列问题 队列的定义：队列是一种特 殊的线性结构,它只允许在队列的首部(head)进行删除操作,这称为“出队”,而在队列 的尾部(tail)进行插入操作,这称为“入队”。当队列中没有元素时(即 head==tail),称为 空队列  《啊哈！算法》中的一道题，大体意思是有一串密码规则为：首先将第 1 个数删除,紧接着将第 2 个数放到 这串数的末尾,">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2016-12-19T08:17:54.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js的简单算法(二)">
<meta name="twitter:description" content="通过一些博客和《啊哈！算法》了解js的栈，队列 队列问题 队列的定义：队列是一种特 殊的线性结构,它只允许在队列的首部(head)进行删除操作,这称为“出队”,而在队列 的尾部(tail)进行插入操作,这称为“入队”。当队列中没有元素时(即 head==tail),称为 空队列  《啊哈！算法》中的一道题，大体意思是有一串密码规则为：首先将第 1 个数删除,紧接着将第 2 个数放到 这串数的末尾,">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://lanbos.win/2016/09/27/reading/arithmetic_fun02/"/>





  <title> js的简单算法(二) | lanbos'blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">lanbos'blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">这个人假装很懒，什么都没有留下</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://lanbos.win/2016/09/27/reading/arithmetic_fun02/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="lanbos">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="https://ws1.sinaimg.cn/large/5c9d16d6gw1fbesf3zrhej209p09ftai.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="lanbos'blog">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="lanbos'blog" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js的简单算法(二)
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-09-27T11:25:22+08:00">
                2016-09-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/coder/" itemprop="url" rel="index">
                    <span itemprop="name">码畜相关</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>通过一些博客和<em>《啊哈！算法》</em>了解js的栈，队列</p>
<h2 id="队列问题"><a href="#队列问题" class="headerlink" title="队列问题"></a>队列问题</h2><blockquote>
<p>队列的定义：队列是一种特 殊的线性结构,它只允许在队列的首部(head)进行删除操作,这称为“出队”,而在队列 的尾部(tail)进行插入操作,这称为“入队”。当队列中没有元素时(即 head==tail),称为 空队列</p>
</blockquote>
<p><em>《啊哈！算法》</em>中的一道题，大体意思是有一串密码规则为：首先将第 1 个数删除,紧接着将第 2 个数放到 这串数的末尾,再将第 3 个数删除并将第 4 个数放到这串数的末尾,再将第 5 个数删除…… 直到剩下最后一个数,将最后一个数也删除。按照刚才删除的顺序,把这些删除的数连在一 起就是这串密码，加密的数字为：“6 3 1 7 5 8 9 2 4”。书中阐述了基本思路，引入两个变量head(剩余数组的第一个元素)和tail(剩余数组的最后一个元素的下一个位置)通过移动head和tail的数值来生成新的数组。代码如下：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> qqArray = [<span class="number">6</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">7</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">2</span>, <span class="number">4</span>];</div><div class="line"><span class="keyword">var</span> sisRight = <span class="function"><span class="keyword">function</span>(<span class="params">arr</span>) </span>&#123;</div><div class="line">  <span class="keyword">var</span> head = <span class="number">0</span>;</div><div class="line">  <span class="keyword">var</span> tail = arr.length;</div><div class="line">  <span class="keyword">var</span> results = [];</div><div class="line">  <span class="keyword">while</span> (head &lt; tail) &#123;</div><div class="line">    results.push(arr[head]);</div><div class="line">    head++;</div><div class="line">    arr[tail] = arr[head];</div><div class="line">    tail++;</div><div class="line">    head++;</div><div class="line">  &#125;</div><div class="line">  <span class="keyword">return</span> results;</div><div class="line">&#125;</div><div class="line">sisRight(qqArray); <span class="comment">//[6, 1, 5, 9, 4, 7, 2, 8, 3]</span></div></pre></td></tr></table></figure></p>
<a id="more"></a>
<h2 id="栈的概念"><a href="#栈的概念" class="headerlink" title="栈的概念"></a>栈的概念</h2><blockquote>
<p>“栈（Stack）是限定仅在表尾进行插入或删除操作的线性表。表尾为栈顶（top），表头为栈底（bottom），不含元素的空表为空栈。栈又称为后进先出（last in first out）的线性表。”</p>
</blockquote>
<p>概念很抽象，大致可模拟理解为只允许一端push和pull的数组。还是通过<em>《啊哈！算法》</em>中的题来理解，题目是判断一个字符串是不是回文字符串（“所谓回文字符 串就是指正读反读均相同的字符序列,如“席主席”、“记书记”、“aha”和“ahaha”均是回 文,但“ahah”不是回文”）。思路是利用回文字符串中心对称的特点来进行解题：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> loopStr = <span class="string">"ahaha"</span>;</div><div class="line"><span class="keyword">var</span> ifLoopStr = <span class="function"><span class="keyword">function</span>(<span class="params">str</span>) </span>&#123;</div><div class="line">  <span class="keyword">var</span> len = str.length;</div><div class="line">  <span class="keyword">var</span> mid = len / <span class="number">2</span> - <span class="number">1</span>;</div><div class="line">  <span class="keyword">var</span> backMid = <span class="built_in">Math</span>.round(len / <span class="number">2</span>);</div><div class="line">  <span class="keyword">var</span> top = <span class="number">-1</span>;</div><div class="line">  <span class="keyword">var</span> s = [];</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt;= mid; i++) &#123;</div><div class="line">    top++;</div><div class="line">    s.push(str[i]);</div><div class="line">  &#125;</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> j = backMid; j &lt; len; j++) &#123;</div><div class="line">    <span class="keyword">if</span> (str[j] != s[top]) &#123;</div><div class="line">      <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line">    &#125;</div><div class="line">    top--;</div><div class="line">  &#125;</div><div class="line">  <span class="keyword">if</span> (top == <span class="number">-1</span>) &#123;</div><div class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line">  &#125; <span class="keyword">else</span> &#123;</div><div class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line">  &#125;</div><div class="line">&#125;</div><div class="line"><span class="built_in">console</span>.log(ifLoopStr(loopStr));<span class="comment">//true</span></div></pre></td></tr></table></figure></p>
<h2 id="纸牌游戏–小猫钓鱼（栈和队列综合问题）"><a href="#纸牌游戏–小猫钓鱼（栈和队列综合问题）" class="headerlink" title="纸牌游戏–小猫钓鱼（栈和队列综合问题）"></a>纸牌游戏–小猫钓鱼（栈和队列综合问题）</h2><p>游戏规则：游戏的规则是这样的:将一副扑克牌平均分成两份,每人拿一份。q1先拿出手中的 第一张扑克牌放在桌上,然后q2也拿出手中的第一张扑克牌,并放在q1刚打出的扑克牌 的上面,就像这样两人交替出牌。出牌时,如果某人打出的牌与桌上某张牌的牌面相同,即35啊哈!算法可将两张相同的牌及其中间所夹的牌全部取走,并依次放到自己手中牌的末尾。当任意一人 手中的牌全部出完时,游戏结束,对手获胜。<br>关键代码逻辑是，建一个作为标记的book数组，长度等于所有牌面的最大数字，然后在其中用0和1存储桌面上是否有出现的牌面。具体代码比较有意思，这里用js模拟了一下。(两人手里各有6张牌，牌面最大为9;q1手里牌是：2, 4, 1, 2, 5, 6；q2手里牌是：3, 1, 3, 5, 6, 4)。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> q1 = &#123;</div><div class="line">  <span class="attr">data</span>: [<span class="number">2</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">5</span>, <span class="number">6</span>],</div><div class="line">  <span class="attr">head</span>: <span class="number">0</span>,</div><div class="line">  <span class="attr">tail</span>: <span class="number">6</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> q2 = &#123;</div><div class="line">  <span class="attr">data</span>: [<span class="number">3</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">4</span>],</div><div class="line">  <span class="attr">head</span>: <span class="number">0</span>,</div><div class="line">  <span class="attr">tail</span>: <span class="number">6</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> cardNum = <span class="number">9</span>;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">playcard</span>(<span class="params">q1, q2, cardNum</span>) </span>&#123;</div><div class="line">  <span class="comment">// init </span></div><div class="line">  <span class="keyword">var</span> _book = [];</div><div class="line">  <span class="keyword">var</span> _s = &#123;</div><div class="line">    <span class="attr">data</span>: [],</div><div class="line">    <span class="attr">top</span>: <span class="number">0</span></div><div class="line">  &#125;</div><div class="line">  <span class="keyword">var</span> _t = <span class="literal">null</span>;</div><div class="line">  <span class="comment">// init s</span></div><div class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; cardNum; i++) &#123;</div><div class="line">    _book.push(<span class="number">0</span>);</div><div class="line">  &#125;</div><div class="line">  <span class="comment">// start play</span></div><div class="line">  <span class="keyword">while</span> (q1.head &lt; q1.tail &amp;&amp; q2.head &lt; q2.tail) &#123;</div><div class="line">    <span class="comment">// q1 put card</span></div><div class="line">    _t = q1.data[q1.head];</div><div class="line">    <span class="keyword">if</span> (_book[_t] == <span class="number">0</span>) &#123; <span class="comment">//q1 continu put</span></div><div class="line">      q1.head++;</div><div class="line">      _s.top++;</div><div class="line">      _s.data[_s.top] = _t;</div><div class="line">      _book[_t] = <span class="number">1</span>;</div><div class="line">    &#125; <span class="keyword">else</span> &#123; <span class="comment">//q1 collect cards</span></div><div class="line">      q1.head++;</div><div class="line">      q1.data[q1.tail] = _t;</div><div class="line">      q1.tail++;</div><div class="line">      <span class="keyword">while</span> (_s.data[_s.top] != _t) &#123;</div><div class="line">        _book[_s.data[_s.top]] = <span class="number">0</span>;</div><div class="line">        q1.data[q1.tail] = _s.data[_s.top];</div><div class="line">        q1.tail++;</div><div class="line">        _s.top--;</div><div class="line">      &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="comment">// q2 put card</span></div><div class="line">    _t = q2.data[q2.head];</div><div class="line">    <span class="keyword">if</span> (_book[_t] == <span class="number">0</span>) &#123; <span class="comment">//q2 continu put</span></div><div class="line">      q2.head++;</div><div class="line">      _s.top++;</div><div class="line">      _s.data[_s.top] = _t;</div><div class="line">      _book[_t] = <span class="number">1</span>;</div><div class="line">    &#125; <span class="keyword">else</span> &#123; <span class="comment">//q2 collect cards</span></div><div class="line">      q2.head++;</div><div class="line">      q2.data[q2.tail] = _t;</div><div class="line">      q2.tail++;</div><div class="line">      <span class="keyword">while</span> (_s.data[_s.top] != _t) &#123;</div><div class="line">        _book[_s.data[_s.top]] = <span class="number">0</span>;</div><div class="line">        q2.data[q2.tail] = _s.data[_s.top];</div><div class="line">        q2.tail++;</div><div class="line">        _s.top--;</div><div class="line">      &#125;</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">  <span class="comment">// win or lose</span></div><div class="line">  <span class="keyword">if</span> (q2.head == q2.tail) &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"q1 win and his cards:"</span>);</div><div class="line">    <span class="keyword">var</span> _results = [];</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = q1.head; i &lt;= q1.tail - <span class="number">1</span>; i++) &#123;</div><div class="line">      _results.push(q1.data[i]);</div><div class="line">    &#125;</div><div class="line">    <span class="built_in">console</span>.log(_results);</div><div class="line">    <span class="keyword">if</span> (_s.top &gt; <span class="number">0</span>) &#123;</div><div class="line">      <span class="keyword">var</span> deskR = [];</div><div class="line">      <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">1</span>; i &lt;= _s.top; i++) &#123;</div><div class="line">        deskR.push(_s.data[i]);</div><div class="line">      &#125;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">"cards on desk:"</span> + deskR);</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">"desk empty"</span>);</div><div class="line">    &#125;</div><div class="line">  &#125; <span class="keyword">else</span> &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"q2 win and his cards:"</span>);</div><div class="line">    <span class="keyword">var</span> _results = [];</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = q2.head; i &lt;= q2.tail - <span class="number">1</span>; i++) &#123;</div><div class="line">      _results.push(q2.data[i]);</div><div class="line">    &#125;</div><div class="line">    <span class="built_in">console</span>.log(_results);</div><div class="line">    <span class="keyword">if</span> (_s.top &gt; <span class="number">0</span>) &#123;</div><div class="line">      <span class="keyword">var</span> deskR = [];</div><div class="line">      <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">1</span>; i &lt;= _s.top; i++) &#123;</div><div class="line">        deskR.push(_s.data[i]);</div><div class="line">      &#125;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">"cards on desk:"</span> + deskR);</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">"desk empty"</span>);</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">"end"</span>);</div><div class="line">&#125;</div><div class="line">playcard(q1, q2, cardNum);</div></pre></td></tr></table></figure></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/算法/" rel="tag"># 算法</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/09/26/reading/arithmetic_fun01/" rel="next" title="js的简单算法">
                <i class="fa fa-chevron-left"></i> js的简单算法
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/10/08/FE/vue_base01/" rel="prev" title="js的mvvm（1）">
                js的mvvm（1） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>
  <!-- UY BEGIN -->
<div id="uyan_frame"></div>
<script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid=2123221"></script>
<!-- UY END -->



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://ws1.sinaimg.cn/large/5c9d16d6gw1fbesf3zrhej209p09ftai.jpg"
               alt="lanbos" />
          <p class="site-author-name" itemprop="name">lanbos</p>
          <p class="site-description motion-element" itemprop="description">这个人假装很懒，什么都没有留下</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">24</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#队列问题"><span class="nav-number">1.</span> <span class="nav-text">队列问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#栈的概念"><span class="nav-number">2.</span> <span class="nav-text">栈的概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#纸牌游戏–小猫钓鱼（栈和队列综合问题）"><span class="nav-number">3.</span> <span class="nav-text">纸牌游戏–小猫钓鱼（栈和队列综合问题）</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lanbos</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  

  

  

  

  


</body>
</html>
